package com.fiveflavors.suittar;

import java.net.URL;

public class SuittarCommand {
	
	public static final int COMMAND_SHOW_PUBLIC = 0;
	
	public static final int COMMAND_SHOW_FRIENDS = 1;
	
	public static final int COMMAND_SHOW_PROFILE = 2;
	
	public static final int COMMAND_SHOW_REPLIES = 3;
	
	public static final int COMMAND_SHOW_FOLLOWERS = 10;

	public static final int COMMAND_SHOW_FOLLOWING = 11;

	public static final int COMMAND_SHOW_DIRECT_MESSAGE = 12;

	public static final int COMMAND_UPDATE_STATUS = 60;
	
	public static final int COMMAND_SEND_DIRECT_MESSAGE = 70;

	public static final int COMMAND_ADD_FRIEND = 80;

	public static final int COMMAND_REMOVE_FRIEND = 90;

	
	private static int command = COMMAND_SHOW_PUBLIC;
	
	private static String screenName = "";
	
	private static int page = 0;
	
	private static boolean execFromTimer = false;
	
	private static boolean commandChanged = false;
	
	public static void initialize(int command,String screenName,int page) {
		SuittarCommand.command = command;
		SuittarCommand.screenName = screenName;
		SuittarCommand.page = page;
		setExecFromTimer(false);
	}
	
	public static int getCommand() {
		return command;
	}

	public static void setCommand(URL commandURL) {
		String queryString = commandURL.getQuery();
		if (queryString != null) {
			String[] queries = queryString.split("&");
			for (String query:queries) {
				String[] keyValue = query.split("=");
				if (keyValue.length == 2) {
					if ("command".equals(keyValue[0].trim())) {
						SuittarCommand.setCommand(Integer.parseInt(keyValue[1]));
					}
					if ("id".equals(keyValue[0].trim())) {
						SuittarCommand.setScreenName(keyValue[1]);
					}
					if ("page".equals(keyValue[0].trim())) {
						SuittarCommand.setPage(Integer.parseInt(keyValue[1]));
					}
				}
			}
		}
	}
	
	public static void setCommand(int command) {
		commandChanged = (SuittarCommand.command != command);
		SuittarCommand.command = command;
	}

	public static String getScreenName() {
		return screenName;
	}

	public static void setScreenName(String screenName) {
		SuittarCommand.screenName = screenName;
	}

	public static int getPage() {
		return page;
	}

	public static void setPage(int page) {
		SuittarCommand.page = page;
	}

	public static boolean isExecFromTimer() {
		return execFromTimer;
	}

	public static void setExecFromTimer(boolean execFromTimer) {
		SuittarCommand.execFromTimer = execFromTimer;
	}
	
	public static boolean isCommandChanged() {
		return commandChanged;
	}

	public static void setCommandChanged(boolean commandChanged) {
		SuittarCommand.commandChanged = commandChanged;
	}
	
}
